//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories {
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class ResumeRepository : BaseRepository, IResumeRepository {
        public ResumeRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork) {
        }
        public void Create(Resume resume) {
            this.GetDbSet<Resume>().Add(resume);
            this.UnitOfWork.SaveChanges();
        }

        public Resume GetResume(Guid resumeId) {
            return this.GetDbSet<Resume>()
                .Where(c => c.Id == resumeId)
                .Single();
        }

        public void Update(Resume updatedResume) {
            this.GetDbSet<Resume>().Attach(updatedResume);
            this.SetEntityState(updatedResume, updatedResume.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid resumeId) {
            Resume ResumeToDelete = this.GetResume(resumeId);
            this.GetDbSet<Resume>().Remove(ResumeToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<Resume> Find()
        {
            return this.GetDbSet<Resume>();
        }

        public IQueryable<Resume> GetAll()
        {
            return this.GetDbSet<Resume>();
        }
    }
}
